@extends('home.default')
@section('content')
<!-- banner部分 -->
<div class="banner news" style="background: url('/storage/uploads/{{isset($banners->pic)?$banners->pic:""}}') no-repeat center top;background-size: cover;">
  <div class="title">
    <p>{{ isset($banners->title)?$banners->title:"" }}</p>
    <p class="en">{{ isset($banners->entitle)?$banners->entitle:"" }}</p>
  </div>
</div>
<!-- main部分 -->
<div class="main-news">
        <div class="layui-container">
          <div class="layui-row layui-col-space20">

                @foreach ($news as $item)
            <div class="layui-col-lg6 content">
              <div>
                <div class="news-img">
                    <a href="{{ route('index.news.show',['news'=>$item->id]) }}">
                            @if($item->pic)
                            <img  src="{{ asset('storage/uploads/'.$item->pic) }}" >
                          @endif
                          @if(!$item->pic)
                          <img  src="{{ asset(__INDEX__) }}/res/static/img/news_img1.jpg" >
                          @endif
                    </a>
                </div>
                <div class="news-panel">
                  <strong><a href="{{ route('index.news.show',['news'=>$item->id]) }}">{{ $item->title }}</a></strong>
                  <p class="detail">
                      <span>{{ $item->remark }}</span>
                      <a href="{{ route('index.news.show',['news'=>$item->id]) }}">[详细]</a>
                    </p>
                  <p class="read-push">阅读
                       <span>{{ $item->views }}</span>&nbsp;&nbsp;&nbsp;&nbsp;发布时间：<span>
                           {{ $item->created_at }}</span>
                    </p>
                </div>
              </div>
            </div>
            @endforeach


          </div>
          <div id="newsPages">{{$news->links('vendor.pagination.default')}}</div>
          {{--  <div id="newsPage"></div>  --}}
        </div>
      </div>
      @section('myjs')
      <script>
            layui.use('laypage', function(){
              var laypage = layui.laypage;

              //执行一个laypage实例
              laypage.render({
                elem: 'newsPage' //注意，这里的 test1 是 ID，不用加 # 号
                ,count: '{{ $news->total() }}' //数据总数，从服务端得到
                ,curr:'{{ $news->currentPage() }}'
                ,jump: function(obj, first){
                    //obj包含了当前分页的所有参数，比如：
                    console.log(obj.curr); //得到当前页，以便向服务端请求对应页的数据。
                    console.log(obj.limit); //得到每页显示的条数

                    //首次不执行
                    if(!first){
                        location.href = "?page="+obj.curr;
                    }
                  }
              });
            });
            </script>
@endsection

